package com.cq.hd.member.controller;

import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbConfigSettingApi;
import com.cq.hd.member.api.dto.ConfigSettingQueryDto;
import com.cq.hd.member.api.dto.ConfigSettingUpdateDto;
import com.cq.hd.member.api.vo.ConfigSettingVo;
import com.cq.hd.member.service.TbConfigSettingService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class TbConfigSettingController implements TbConfigSettingApi {

    @Resource
    private TbConfigSettingService configSettingService;

    @Override
    public Result<Void> setConfigValue(ConfigSettingUpdateDto configSettingUpdateDto) {
        configSettingService.setConfigValue(configSettingUpdateDto);
        return ResultGenerator.success();
    }

    @Override
    public Result<List<ConfigSettingVo>> list(ConfigSettingQueryDto configSettingQueryDto) {
        return ResultGenerator.success(configSettingService.getUserConfigOrDefault(configSettingQueryDto));
    }

    @Override
    public Result<String> getUserConfigValue(Long userId, String configKey) {
        return ResultGenerator.success(configSettingService.getUserConfigValue(userId, configKey));
    }
}
